﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BTalk.Timer
{
    public class DisposableTimer : IDisposable
    {

        private DateTime StartTime { get; set; }
        private string Message { get; set; }
        private bool Disposing { get; set; }

        public DisposableTimer(string message)
        {
            Message = message;
            StartTime = DateTime.Now;
        }

        public void Dispose()
        {
            if (!Disposing)
            {
                Disposing = true;
                TimeSpan difference = DateTime.Now - StartTime;
                Debugger.Log(100, "Performance", String.Format("{0} {1}", Message, difference.ToString()));
            }
        }
    }
}
